//
//  HDPracticeOrderListViewController.m
//  HDecoration
//
//  Created by 曹群 on 15/9/13.
//  Copyright (c) 2015年 HDecoration. All rights reserved.
//

#import "HDPracticeOrderListViewController.h"
#import "HDOrderListTableViewController.h"

@interface HDPracticeOrderListViewController ()
@property(nonatomic,strong)HDOrderListTableViewController *practiceOrderList;
@end

@implementation HDPracticeOrderListViewController

- (void)initUI
{
    _practiceOrderList = [[HDOrderListTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    _practiceOrderList.orderType = HDOrderTypePractice;
    _practiceOrderList.view.frame = self.view.bounds;
    _practiceOrderList.enableRefresh = NO;
    _practiceOrderList.enableRequest = YES;
    [self.view addSubview:_practiceOrderList.tableView];
}
- (void)pullTableView:(UITableView *)tableView isNextPage:(BOOL)isNextPage
{
    self.practiceOrderList.pageNum++;
    [self requestPracticeOrderList:YES];
}

- (void)pullRefreshRequest
{
    self.practiceOrderList.pageNum = 1;
    [self requestPracticeOrderList:YES];
}

-(void)requestPracticeOrderList:(BOOL)isPull
{
    NSString *pageNo = [NSString stringWithFormat:@"%d",self.practiceOrderList.pageNum];
    UIView* hudView=isPull?nil:self.practiceOrderList.view;
    //请求订单信息
    NSDictionary* params=@{
                             @"coach_id":netEngine.coachInfo.m_id,
                             @"order_type":[NSNumber numberWithInt:2],//order_type: 1：学车 2：练车
                             @"page":pageNo,
                             @"row":[NSNumber numberWithInt:20],//每页显示多数行
                             };
    
    [netEngine RequestCoachOrderWithTarget:self.VctrID hudView:hudView Data:params];
}

- (void)updateViewController:(NSNotification *)note
{
    NSDictionary* dic=note.userInfo;
    if ([dic objectForKey:Receiver]==self.VctrID)
    {
        if (dic[@"CoachOrder"]!=nil)
        {
            self.practiceOrderList.totalPagesNum = [[dic objectForKey:@"totalPage"] intValue];
            if (self.practiceOrderList.pageNum==1) {
                self.practiceOrderList.dataArray = nil;
            }
            NSMutableArray *dataArray = [[NSMutableArray alloc] initWithArray:self.practiceOrderList.dataArray];
            [dataArray addObjectsFromArray:dic[@"dataArray"]];
            self.practiceOrderList.dataArray = dataArray;
        }
    }
}

- (void)testDataFunc
{
    self.practiceOrderList.pageNum = 1;
    [self requestPracticeOrderList:NO];
    

}

@end
